<template>
	<view class="content">
		<view class="wid100" style="height: 396rpx;background-color: #035DFF;">
			<view style="height: 40rpx;"></view>
			<view class="coFFF">
				<view class="textCen" style="font-size: 100rpx;">{{integral}}</view>
				<view class="dis disAl disJuC foSi20" @click="jfgz()">
					<uni-icons type="info" size="20rpx" color="#fff"></uni-icons>
					<view class="mar-left10">积分兑换规则</view>
				</view>
				<view style="height: 74rpx;"></view>
				<view class="dis disAl disJuC">
					<view class="dis disAl disJuC borRad40 foSi25 butt" @click="tiaozhuan('/pages/store/storeList')">积分明细</view>
					<view class="dis disAl disJuC borRad40 foSi25 butt" @click="tiaozhuan('/pages/store/exchange?biaoji=0')" style="margin-left: 74rpx;">兑换记录</view>
				</view>
			</view>
		</view>
		<scroll-view class="scroll-view_H wid100 bacFFF" scroll-x="true">
			<block v-for="(item,index) in commodity" :key="index">
				<view class="hei100 wid25" style="display: inline-block;">
					<view class="wh100 dis disJuC">
						<view :style="item.id == id?'border-bottom: 4rpx solid #035DFF;color: #035DFF;':'border-bottom: 4rpx solid #fff;color: #868687;'"
							class="hei86 dis disAl foSi25 fowe600" @click="xuan(item)">{{item.name}}</view>
					</view>
				</view>
			</block>
		</scroll-view>
		<scroll-view style="height: calc(100vh - 500rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<view class="hei20"></view>
			<view class="dis disAl disJuB flwa wid90 mar">
				<block v-for="(item,index) in list" :key="index">
					<view class="borRad20 bacFFF mar-bott30" @click="tiaozhuan('/pages/commodity/commodity?id='+item.id)"
						style="width: 49%;height: 379rpx;">
						<image :src="url+item.pic.split(',')[0]" class="wid100" style="height: 257rpx;border-top-left-radius: 20rpx;border-top-right-radius: 20rpx;"></image>
						<view style="height: 18rpx;"></view>
						<view class="wid90 mar">
							<view class="foSi25 fowe600">{{item.name}}</view>
							<view class="wid100 dis disJuB foSi20" style="align-items: flex-end;">
								<view class="fowe600" style="color: #FF0000;">{{item.price}}积分</view>
								<view class="dis disAl disJuC borRad40 coFFF" @click.stop="tiaozhuan('/pages/commodity/exchange?id='+item.id)" 
									style="width: 80rpx;height: 36rpx;background-color: #035DFF;">兑换</view>
								<!-- @click="duihuan(item.id)" -->
							</view>
						</view>
					</view>
				</block>
				<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35">
					<view style="height: 50rpx;"></view>
					<view class="dis disJuC">
						<image src="../../static/zanwu1.png" style="width: 400rpx;height: 300rpx;"></image>
					</view>
					<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
				</view>
			</view>
		</scroll-view>
		<view class="guize" v-if="jf_index != 0" @click="jfgz">
			<view class="">
				<rich-text :nodes="jfgz_content"></rich-text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				commodity: [{id: 0, name: '全部商品'}],
				id: 0,
				list: [],
				last_page: 0,
				page: 1,
				integral: 0,
				jf_index: 0,
				jfgz_content:"1231332132"
			}
		},
		onLoad() {
			this.getType()
			this.getList()
		},
		methods: {
			jfgz(){
				var that = this;
				if(that.jf_index == 1){
					that.jf_index = 0;
				}else{
					that.jf_index = 1;
				}
			},
			getType() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_goods_type',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.commodity = that.commodity.concat(result.data)
						}
					}
				})
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_goods',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						type_id: that.id,
						page: that.page,
						limit: 10,
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.last_page = result.data.last_page
							that.list = that.list.concat(result.data.data)
							that.jfgz_content = result.data.jfgz_content
							that.integral = result.data.integral
						}
					}
				})
			},
			xuan(item){
				if(this.id != item.id){
					this.id = item.id
					this.list = []
					this.page = 1
					this.getList()
				}
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			tiaozhuan(url){
				var userinfo = uni.getStorageSync('userinfo')
				if(!userinfo){
					uni.switchTab({
						url: '/pages/wode/wode'
					})
				}else{
					uni.navigateTo({
						url: url
					})
				}
			}
		}
	}
</script>

<style>
	.content {
		background-color: #F8F9FD;
		height: 100vh;
	}
	.butt{
		width: 201rpx;
		height: 56rpx;
		border: 1rpx solid #fff;
	}
	.scroll-view_H {
		white-space: nowrap;
		height: 90rpx;
		box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);
	}
	.guize{
		position: absolute;
		z-index: 999999;
		background-color:rgba(0,0,0,0.5);
		width: 100%;
		height: 100vh;
		top: 0%;
		left: 0%;
	}
	.guize view{
		position: absolute;
		color: #fff;
		z-index: 999999;
		background-color:rgba(85, 170, 255, 1);
		border-radius: 10px;
		width: 76%;
		padding: 2%;
		height: 300rpx;
		top: 20%;
		left: 10%;
	}
</style>
